
package ch.hearc.meteo.imp.afficheur.real.vue;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;

import ch.hearc.meteo.tools.ImageShop;

public class JPanelListeStationMeteoFilter extends JPanel
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/
	public JPanelListeStationMeteoFilter(JPanelListeStationMeteo panelListeStationMeteo)
		{
		this.panelListeStationMeteo = panelListeStationMeteo;
		geometry();
		control();
		apparence();
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	/*------------------------------*\
	|*				Set				*|
	\*------------------------------*/

	/*------------------------------*\
	|*				Get				*|
	\*------------------------------*/
	public void updateMeteoStationList()
		{
		panelListeStationMeteo.applyMeteoStationFilter(txtStationMeteoFilter.getText());
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	private void geometry()
		{
		this.setLayout(new FlowLayout(FlowLayout.LEFT));
		txtStationMeteoFilter = new JTextField();

		btnClearFilter = new JButton(new ImageIcon(ImageShop.IMAGE_ERASE));
		btnClearFilter.setRolloverIcon(new ImageIcon(ImageShop.IMAGE_ERASE_HOVER));
		btnClearFilter.setOpaque(false);
		btnClearFilter.setBorder(BorderFactory.createEmptyBorder());

		this.add(txtStationMeteoFilter);
		this.add(btnClearFilter);
		}

	private void control()
		{
		btnClearFilter.addActionListener(new ActionListener()
			{

				@Override
				public void actionPerformed(ActionEvent event)
					{
					txtStationMeteoFilter.setText("");
					txtStationMeteoFilter.requestFocus();
					}
			});
		txtStationMeteoFilter.addCaretListener(new CaretListener()
			{

				@Override
				public void caretUpdate(CaretEvent arg0)
					{
					panelListeStationMeteo.applyMeteoStationFilter(txtStationMeteoFilter.getText());

					}
			});

		}

	private void apparence()
		{
		txtStationMeteoFilter.setPreferredSize(new Dimension(190, 25));
		btnClearFilter.setPreferredSize(new Dimension(35, 25));
		}

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/

	//Input
	private JPanelListeStationMeteo panelListeStationMeteo;

	//Tools
	private JTextField txtStationMeteoFilter;
	private JButton btnClearFilter;
	}
